package juc.concurrent.exchanger;

import java.util.concurrent.Exchanger;

//线程通信
public class ExchangerDemo2 extends Thread {
    private Exchanger<String> exchanger;

    ExchangerDemo2(Exchanger<String> exchanger){
        this.exchanger = exchanger;
    }
    @Override
    public void run() {
        try {
            System.out.println("在线程B中得到线程A的值:" + exchanger.exchange("中国人B"));
            System.out.println("B end");
        }catch (Exception e){
            e.printStackTrace();
        }
    }
}
